#pragma once
#ifndef __SINGLETON_HEADER__
#define __SINGLETON_HEADER__

template <typename T>
class ISingleton
{
public:
	ISingleton()
	{
		assert(!ms_Singleton && "ISingleton(): Singleton instance already exists!");
		int offset = (int)(T*)1 - (int)(ISingleton<T>*)(T*)1;
		ms_Singleton = (T*)((int)this + offset);
	}
	~ISingleton()
	{
		assert(ms_Singleton && "~ISingleton(): Singleton instance doesn't exist!");
		ms_Singleton = 0;
	}
	inline static T& Get()
	{
		assert(ms_Singleton && "singleton Get(): Singleton instance doesn't exist!");
		return *ms_Singleton;
	}
	inline static T* GetPtr()
	{
		assert(ms_Singleton && "singleton GetPtr(): Singleton instance doesn't exist!");
		return ms_Singleton;
	}
	inline static const bool Exist() { return ms_Singleton != 0; }

private:
	static T* ms_Singleton;
};

template <typename T> T* ISingleton<T>::ms_Singleton = 0;

#endif // #ifndef __SINGLETON_HEADER__